#!/usr/bin/ruby
 
require 'mcollective'
  
include MCollective::RPC
 
options = rpcoptions do |parser, options|
   parser.define_head "Generic File Manager Client"
   parser.banner = "Usage: mc-filemgr [--file FILE] [touch|remove]"

   parser.on('-f', '--file MSG', 'Message to pass') do |v|
      options[:file] = v
   end
end

if ARGV.length == 1
    command = ARGV.shift
else
    command = "touch"
end

mc = rpcclient("filemgr", :options => options)

if command == "remove"
    unless options.include?(:file)
        puts "remove command requires --file FILE"
        exit 1
    end
    printrpc mc.remove(:file => options[:file])

elsif command == "touch"
    if options[:file]
        printrpc mc.touch(:file => options[:file])
    else
        printrpc mc.touch()
    end

else
    puts "Valid commands are 'touch' and 'remove'"
    exit 1
end

printrpcstats
